
exports.__esModule = true;
exports.default = void 0;

const _utils = require('../utils');

const _relation = require('../mixins/relation');

const _createNamespace = (0, _utils.createNamespace)('col');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

const _default = createComponent({
  mixins: [(0, _relation.ChildrenMixin)('vanRow')],
  props: {
    span: [Number, String],
    offset: [Number, String],
    tag: {
      type: String,
      default: 'div',
    },
  },
  computed: {
    gutter: function gutter() {
      return this.parent && Number(this.parent.gutter) || 0;
    },
    style: function style() {
      const { index } = this;
      const { gutter } = this;

      if (gutter) {
        const count = this.parent.children.length;
        const padding = gutter * (count - 1) / count;

        if (index === 0) {
          return {
            paddingRight: `${padding}px`,
          };
        }

        if (index === count - 1) {
          return {
            paddingLeft: `${padding}px`,
          };
        }

        return {
          paddingLeft: `${padding / 2}px`,
          paddingRight: `${padding / 2}px`,
        };
      }
    },
  },
  methods: {
    onClick: function onClick(event) {
      this.$emit('click', event);
    },
  },
  render: function render() {
    let _bem;

    const h = arguments[0];
    const { span } = this;
    const { offset } = this;
    return h(this.tag, {
      style: this.style,
      class: bem((_bem = {}, _bem[span] = span, _bem[`offset-${offset}`] = offset, _bem)),
      on: {
        click: this.onClick,
      },
    }, [this.slots()]);
  },
});

exports.default = _default;
